J.Drag = new Class({
    options: {
        delay: 100,
        start: function () { return true },
        drag: function () { return true },
        end: function () { return true }
    },
    value: {},
    initialize: function (el, o) {
        var This = this;
        if (o) this.setOptions(o);
        var handle = {
            start: function (e) {
                This.value.start = setTimeout(function () {
                    This.value.startDrag = {
                        x: e.clientX,
                        y: e.clientY
                    }
                    document.addEvent('mousemove', handle.drag);
                    This.options.start.call(This, e);

                   
                }, This.options.delay);
                document.addEvent('mouseup', handle.end);
                document.onmousedown = function () { return false };
                document.onselectstart = function () { return false };
            },
            drag: function (e) {
                This.value.drag = true;
                e.move = {
                    x: e.clientX - This.value.startDrag.x,
                    y: e.clientY - This.value.startDrag.y
                }
                This.options.drag.call(this, e);
            },
            end: function (e) {
                clearTimeout(This.value.start);
                if (This.value.startDrag) {
                    e.move = {
                        x: e.clientX - This.value.startDrag.x,
                        y: e.clientY - This.value.startDrag.y
                    }                    
                    This.options.end.call(this, e);
                    document.removeEvent('mousemove', handle.drag);                    
                    This.value.startDrag = null;
                    This.value.drag = false;
                }

                document.removeEvent('mouseup', handle.end);
                document.onmousedown = null;
                document.onselectstart = null;
            }
        }
        el.addEvent('mousedown', handle.start);
    },
    destroy: function () {
        el.removeEvent('mousedown', this.start);
    }
}).extend(new Options);